﻿using System.Collections.Generic;
using OscarClover.Packets;

namespace OscarClover
{
    public class TlvList : List<Tlv>
    {
        public Tlv this[ushort tag]
        {
            get
            {
                Tlv result = null;
                foreach (Tlv tlv in this)
                {
                    if (!tlv.Tag.Equals(tag)) continue;
                    result = tlv;
                    break;
                }
                return result;
            }
            set
            {
                var flag = false;
                foreach (Tlv tlv in this)
                {
                    if (!tlv.Tag.Equals(tag)) continue;
                    tlv.Len = value.Len;
                    tlv.Value = value.Value;
                    flag = true;
                    break;
                }
                if (flag) return;
                Add(value);
                Sort();
            }
        }
    }
}
